// formRules.ts
import type { Rule } from 'ant-design-vue/es/form/interface'

// 昵称校验规则
export const nameRules: Rule[] = [
  {
    required: true,
    message: '请输入昵称',
    trigger: 'change',
  },
  { min: 2, max: 5, message: '昵称长度在2到5个字之间', trigger: 'blur' },
]

// 真实姓名校验规则
export const realNameRules: Rule[] = [
  {
    required: true,
    message: '请输入真实姓名',
    trigger: 'change',
  },
  {
    pattern: /^[\u4e00-\u9fa5]{2,10}$/,
    message: '真实姓名只能包含中文汉字，且长度在2到10个字之间',
    trigger: 'blur',
  },
]

// 常用邮箱校验规则
export const emailRules: Rule[] = [
  {
    required: true,
    message: '请输入常用邮箱',
    trigger: 'change',
  },
  {
    pattern: /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/,
    message: '请输入正确的邮箱格式',
    trigger: 'blur',
  },
]

// 手机号码校验规则
export const mobilePhone: Rule[] = [

  {
    required: true,
    message: '请输入手机号码',
    trigger: 'change',
  },
  {
    pattern: /^1[3-9]\d{9}$/,
    message: '手机号码格式不正确',
    trigger: 'blur',
  },
]

// QQ号码校验规则
export const qqRules: Rule[] = [
  {
    required: true,
    message: '请输入QQ号',
    trigger: 'change',
  },
  {
    pattern: /^\d{5,11}$/,
    message: 'QQ号必须是5到11位的数字',
    trigger: 'blur',
  },
]

// 将所有校验规则整合到一个对象中以便于使用
export const formRules: Record<string, Rule[]> = {
  nickname: nameRules,
  realName: realNameRules,
  email: emailRules,
  phoneCode: mobilePhone,
  qqCode: qqRules,
}
